package com.example.springdatajpa.entity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 实体类
 */
@Entity
@Table(name = "zocai_order")
@Component
@Getter
@Setter
@Data
public class Order {

    @Id
    //@GenericGenerator(name = "idGenerator",strategy = GenerationType.IDENTITY)
    @GeneratedValue(strategy = GenerationType.AUTO)
    @JsonSerialize(using= ToStringSerializer.class)
    private Long id;

    @Column(name = "userid")
    @JsonSerialize(using= ToStringSerializer.class)
    private Long userId;

    @Column(name = "addrId")
    @JsonSerialize(using= ToStringSerializer.class)
    private Long addrId;

    @Column(name = "statuId")
    private Integer statuId;

    @Column(name = "note")
    private String note;

    @Column(name = "createDate")
    private Date createDate;

    @Column(name = "modityDate")
    private Date modityDate;

    @Column(name = "total")
    private Double total;

    @Column(name = "sum")
    private Integer sum;

    @Column(name = "payid")
    private String payId;

    @Column(name = "payMessage")
    private String payMessage;

    @Column(name = "payStatu")
    private String payStatu;

    @Column(name = "payCreateDate")
    private String payCreateDate;

    @Column(name = "payModifyDate")
    private String payModifyDate;

    @OneToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
    @JoinColumn(name = "orderId",referencedColumnName = "id")
    private Set<OrderDetail> orderDetails = new HashSet<>();

    @Override
    public String toString() {
        return "Order{" +
                "id=" + id +
                ", userId=" + userId +
                ", addrId=" + addrId +
                ", statuId=" + statuId +
                ", note='" + note + '\'' +
                ", createDate=" + createDate +
                ", modityDate=" + modityDate +
                ", total=" + total +
                ", sum=" + sum +
                ", payId='" + payId + '\'' +
                ", payMessage='" + payMessage + '\'' +
                ", payStatu='" + payStatu + '\'' +
                ", payCreateDate='" + payCreateDate + '\'' +
                ", payModifyDate='" + payModifyDate + '\'' +
                ", orderDetails='" + orderDetails + '\'' +
                '}';
    }


}
